<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="js/jquery.min.js" type="text/javascript"></script>
<link href="css/zhu/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<link href="css/zhu/memberrole.css" rel="stylesheet">
<link href="css/zhu/Administrators.css" rel="stylesheet">
<script type="text/javascript">
	$(function() {
		$("#tijiaoadmin").click(function() {
			//获得姓名，管理员账号，密码，角色
			var adminname = $("input[name=adminname]").val();
			var admin = $("input[name=admin]").val();
			var adminpass = $("input[name=adminpass]").val();
			var role = $("select[name=role]").val();
			if (adminname == null || adminname == "") {
				$(".phone_tips > span").html("姓名不能为空！");
				$("input[name=adminname]").focus();
				return;
			} else if (admin == null || admin == "") {
				$(".pwd1_tips > span").html("管理员账号不能为空！");
				$("input[name=admin]").focus();
				return;
			} else if (adminpass == null || adminpass == "") {
				$(".pwd2_tips > span").html("密码不能为空！");
				$("input[name=adminpass]").focus();
				return;
			} else if (role == null || role == "") {
				$(".pwd3_tips > span").html("角色不能为空！");
				$("select[name=role]").focus();
				return;
			} else {
				$(".admin_form").submit();
			}
		})
		//删除
		$("[adminshanchu]").click(function() {
			//获得ID
			var zhehang = $(this);
			var adminid = $(this).attr("adminshanchu");
			$.get("deleteAdminid", {
				adminid : adminid
			}, function(data, success) {
				if (data == "22") {
					alert("删除成功！");
					console.log($(this).parent().parent());
					zhehang.parent().parent().remove();
				}
			}, "text");
		})
		$("[tijiaoadminmodify]").click(function() {
			var tr = $(this).parent().prev().find("tr");
			var admin_name = tr.eq(0).find("input").val();
			var admin_username = tr.eq(1).find("input").val();
			var admin_password = tr.eq(2).find("input").val();
			var admin_role = tr.eq(3).find("select").val();
			var admin_id = tr.eq(4).find("input").val();
			$.post("modifyadmin", {
				adminxiugai : admin_id,
				adminnamemodify : admin_name,
				adminmodify : admin_username,
				adminpassmodify : admin_password,
				rolemodify : admin_role
			}, function(data, success) {
				alert(data);
				location.href = "/fuhe/zhu";
			})
		})
	});
</script>
</head>
<body>
	<!--
        	作者：offline
        	时间：2017-10-30
        	描述：管理员管理
        -->
	<!-- 判断是否有访问该页面的权限 -->
	<c:set var="isDoing" value="0" />
	<c:forEach items="${powerList}" var="power" varStatus="status">

		<c:if test="${power.name=='管理员管理' && isDoing==0}" var="u">
			<!--  设置跳出 条件 -->
			<c:set var="isDoing" value="1" />
			<!-- 管理员页面 -->
			<div class="zuidadiv">
				<div class="zuishangdiv">管理员管理</div>
				<div class="zhongjiandiv">
					<ul>
						<li>
							<button type="button" class="btn btn-primary" data-toggle="modal"
								data-target="#myModal7">添加</button>
							<div class="modal fade" id="myModal7" tabindex="-1" role="dialog"
								aria-labelledby="myModalLabel">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<button data-dismiss="modal" class="close" type="button">
												<span aria-hidden="true">×</span><span class="sr-only">Close</span>
											</button>
											<h4 class="modal-title">添加</h4>
										</div>
										<div class="modal-body">
											<form action="/fuhe/addadmin" class="admin_form"
												method="post" style="padding-left: 85px">
												<input type="hidden" value="" />
												<table border="0" cellspacing="0" cellpadding="0">
													<tbody>
														<tr>
															<td>名称：</td>
															<td><input name="adminname" type="text">
																<div class="phone_tips">
																	<span style="color: red"></span>
																</div></td>
														</tr>
														<tr>
															<td>管理员账号：</td>
															<td><input name="admin" type="text">
																<div class="pwd1_tips">
																	<span style="color: red"></span>
																</div></td>
														</tr>
														<tr>
															<td>密码：</td>
															<td><input name="adminpass" type="text">
																<div class="pwd2_tips">
																	<span style="color: red"></span>
																</div></td>
														</tr>
														<tr>
															<td>角色：</td>
															<td><select name="role">
																	<option value="">--请选择--</option>
																	<c:forEach items="${rol}" var="ro">
																		<option value="${ro.id}">${ro.name}</option>
																	</c:forEach>

															</select>
																<div class="pwd3_tips">
																	<span style="color: red"></span>
																</div></td>
														</tr>
													</tbody>
												</table>
											</form>
										</div>
										<div class="modal-footer">
											<button data-dismiss="modal" class="btn btn-default"
												type="button">关闭</button>
											<button class="btn btn-primary" id="tijiaoadmin"
												type="button">提交</button>
										</div>
									</div>
									<!-- /.modal-content -->
								</div>
								<!-- /.modal-dialog -->
							</div>

						</li>
					</ul>
				</div>
				<div>
					<table width="100%" border="0" cellspacing="0" cellpadding="0"
						class="tablelist table table-striped table-bordered table-hover  table-condensed"
						id="myTable">
						<thead>
							<th width="15%">名称</th>
							<th width="17%">管理员账号</th>
							<th width="10%">密码</th>
							<th width="17%">角色</th>
							<th width="23%">qq</th>
							<th width="17%">操作</th>
						</thead>
						<tbody>
							<c:forEach items="${adm}" var="ad">
								<tr>
									<td>${ad.name}</td>
									<td>${ad.username}</td>
									<td>${ad.password}</td>
									<td>${ad.rolename}</td>
									<td>无</td>
									<td>
										<button type="button" class="btn btn-primary"
											data-toggle="modal" data-target="#myModalxiugai${ad.id}">修改</button>
										<div class="modal fade" id="myModalxiugai${ad.id}"
											tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
											<div class="modal-dialog">
												<div class="modal-content">
													<div class="modal-header">
														<button data-dismiss="modal" class="close" type="button">
															<span aria-hidden="true">×</span><span class="sr-only">Close</span>
														</button>
														<h4 class="modal-title">修改</h4>
													</div>
													<div class="modal-body">
														<form method="post" style="padding-left: 85px">
															<input type="hidden" value="" />
															<table border="0" cellspacing="0" cellpadding="0">
																<tbody>
																	<tr>
																		<td>名称：</td>
																		<td><input name="adminnamemodify" type="text"
																			value="${ad.name }">
																			<div class="modifyphone_tips">
																				<span style="color: red"></span>
																			</div></td>
																	</tr>
																	<tr>
																		<td>管理员账号：</td>
																		<td><input name="adminmodify" type="text"
																			value="${ad.username}" />
																			<div class="modifypwd1_tips">
																				<span style="color: red"></span>
																			</div></td>
																	</tr>
																	<tr>
																		<td>密码：</td>
																		<td><input name="adminpassmodify" type="text"
																			value="${ad.password}" />
																			<div class="modifypwd2_tips">
																				<span style="color: red"></span>
																			</div></td>
																	</tr>
																	<tr>
																		<td>角色：</td>
																		<td><select name="rolemodify">

																				<c:forEach items="${rol}" var="ro">
																					<c:if test="${ad.rolename==ro.name}">
																						<option selected="selected" value="${ro.id}">${ro.name}</option>
																					</c:if>
																					<option value="${ro.id}">${ro.name}</option>
																				</c:forEach>
																		</select>
																			<div class="modifypwd3_tips">
																				<span style="color: red"></span>
																			</div></td>
																	</tr>
																	<tr style="display: none">
																		<td></td>
																		<td><input name="adminxiugai" type="text"
																			value="${ad.id}" style="display: none" /></td>
																	</tr>
																</tbody>
															</table>
														</form>
													</div>
													<div class="modal-footer">
														<button data-dismiss="modal" class="btn btn-default"
															type="button">关闭</button>
														<button class="btn btn-primary"
															tijiaoadminmodify="${ad.id}" type="button">提交</button>
													</div>
												</div>
												<!-- /.modal-content -->
											</div>
											<!-- /.modal-dialog -->
										</div>
										<button type="button" class="btn btn-danger"
											adminshanchu="${ad.id}">删除</button>
									</td>
									<td style="display: none">${ad.id}</td>

								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</c:if>
		<c:if test="${fn:length(powerList) == status.count && isDoing==0 }">
			<c:if test="${!u }">
				<jsp:include page="403.jsp"></jsp:include>
			</c:if>
		</c:if>
	</c:forEach>
</body>
</html>